import pytest

# -*- coding:utf-8 -*-
import getopt
import os
import sys
import time
import pytest
from base.common_keys import keyWords
import requests
import threading
import multiprocessing


def get_env():
    # env = getopt.getopt(sys.argv, '-h')
    # return env[1][1]
    return 'SIT'  # 调试用


def get_test_case():
    # case = getopt.getopt(sys.argv, '-h')
    # return case[1][2]
    # return 'API-全量应付流程'  # 调试用
    return 'test_a'  # 调试用


def run_local():
    pytest.main(
        ['-vs', '-m flow_full', '--alluredir',
         os.path.dirname(__file__) + './report/allure_temp/', '--clean-alluredir'])
    os.system("allure generate " + os.path.dirname(__file__) + "./report/allure_temp/ -o " + os.path.dirname(
        __file__) + "./report/allure_report_%s --clean" % get_env())


def run_jenkins_local():
    pytest.main(
        ['-vs', '-m flow_full', os.path.dirname(__file__) + f'/api_flow/Rokin_{get_test_case()}.py', '--alluredir',
         rf'D:\Jenkins\workspace\{get_test_case()}\allure-temp', '--clean-alluredir', '--cache-clear'])


def run_jenkins_service():
    if get_env() == 'SIT':
        allure_dir = f'/root/.jenkins/workspace/test1/{get_test_case()}/allure-results'
        pytest.main(
            ['-vs', '-m flow_full', f'/home/liuyu/software/Api/pythonProject3/api_flow/{get_test_case()}.py', '--alluredir', allure_dir, '--clean-alluredir']
        )
    elif get_env() == 'UAT':
        pytest.main(
            ['-vs', '-m flow_full', os.path.dirname(__file__) + f'/api_flow/{get_test_case()}.py', '--alluredir',
             rf'/home/liuyu/software/API-UAT/{get_test_case()}-UAT/allure-temp/', '--clean-alluredir'])


def run_multiprocessing():
    for i in range(1):
        print("==========================当前执行到第：" + str(i) + "次=================================")
        run_jenkins_local()


if __name__ == '__main__':
    # run_jenkins_local()
    # run_jenkins_service()
    # print('测试1'+os.path.dirname(__file__) + f'/api_flow/Rokin_{get_test_case()}.py')
    run_local()
    # 多线程执行
    # process1 = multiprocessing.Process(target=run_multiprocessing)
    # process2 = multiprocessing.Process(target=run_multiprocessing)
    # process3 = multiprocessing.Process(target=run_multiprocessing)
    #
    # process1.start()
    # time.sleep(5)
    # process2.start()
    # time.sleep(5)
    # process3.start()
    #
    # process1.join()
    # process2.join()
    # process3.join()
    # print("#############################执行完毕###################################")
